package com.example.fruitdemo.commn;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component

@Slf4j
public class MetaFiled implements MetaObjectHandler {
    //添加时自动填充公共字段
    @Override
    public void insertFill(MetaObject metaObject) {
         log.info("公共字段自动填充[insert]");
         log.info(metaObject.toString());
         metaObject.setValue("createtime", LocalDateTime.now());
         metaObject.setValue("updatetime",LocalDateTime.now());
    }
    //修改时自动填充公共字段
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("公共字段自动填充[update]");
      log.info(metaObject.toString());
        metaObject.setValue("updatetime",LocalDateTime.now());
    }
}